home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / atarifb.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  5KB  |  242 lines

  1. /***************************************************************************
  2.  
  3. Atari Football machine
  4.  
  5. If you have any questions about how this driver works, don't hesitate to
  6. ask.  - Mike Balfour (mab22@po.cwru.edu)
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. static int CTRLD;
  14. static int sign_x_1, sign_y_1;
  15. static int sign_x_2, sign_y_2;
  16. static int sign_x_3, sign_y_3;
  17. static int sign_x_4, sign_y_4;
  18.  
  19. WRITE_HANDLER( atarifb_out1_w )
  20. {
  21.     CTRLD = data;
  22.     /* we also need to handle the whistle, hit, and kicker sound lines */
  23. //    logerror("out1_w: %02x\n", data);
  24. }
  25.  
  26. WRITE_HANDLER( atarifb4_out1_w )
  27. {
  28.     CTRLD = data;
  29.     coin_counter_w (0, data & 0x80);
  30.     /* we also need to handle the whistle, hit, and kicker sound lines */
  31. //    logerror("out1_w: %02x\n", data);
  32. }
  33.  
  34. WRITE_HANDLER( soccer_out1_w )
  35. {
  36.     /* bit 0 = whistle */
  37.     /* bit 1 = hit */
  38.     /* bit 2 = kicker */
  39.     /* bit 3 = unused */
  40.     /* bit 4 = 2/4 Player LED */
  41.     /* bit 5-6 = trackball CTRL bits */
  42.     /* bit 7 = Rule LED */
  43.     CTRLD = data;
  44.     osd_led_w (0, (data & 0x10) >> 4);
  45.     osd_led_w (1, (data & 0x80) >> 7);
  46. }
  47.  
  48.  
  49. READ_HANDLER( atarifb_in0_r )
  50. {
  51.     if ((CTRLD & 0x20)==0x00)
  52.     {
  53.         int val;
  54.  
  55.         val = (sign_y_2 >> 7) |
  56.               (sign_x_2 >> 6) |
  57.               (sign_y_1 >> 5) |
  58.               (sign_x_1 >> 4) |
  59.               input_port_0_r(offset);
  60.         return val;
  61.     }
  62.     else
  63.     {
  64.         static int counter_x,counter_y;
  65.         int new_x,new_y;
  66.  
  67.         /* Read player 1 trackball */
  68.         new_x = readinputport(3);
  69.         if (new_x != counter_x)
  70.         {
  71.             sign_x_1 = (new_x - counter_x) & 0x80;
  72.             counter_x = new_x;
  73.         }
  74.  
  75.         new_y = readinputport(2);
  76.         if (new_y != counter_y)
  77.         {
  78.             sign_y_1 = (new_y - counter_y) & 0x80;
  79.             counter_y = new_y;
  80.         }
  81.  
  82.         return (((counter_y & 0x0f) << 4) | (counter_x & 0x0f));
  83.     }
  84. }
  85.  
  86.  
  87. READ_HANDLER( atarifb_in2_r )
  88. {
  89.     if ((CTRLD & 0x20)==0x00)
  90.     {
  91.         return input_port_1_r(offset);
  92.     }
  93.     else
  94.     {
  95.         static int counter_x,counter_y;
  96.         int new_x,new_y;
  97.  
  98.         /* Read player 2 trackball */
  99.         new_x = readinputport(5);
  100.         if (new_x != counter_x)
  101.         {
  102.             sign_x_2 = (new_x - counter_x) & 0x80;
  103.             counter_x = new_x;
  104.         }
  105.  
  106.         new_y = readinputport(4);
  107.         if (new_y != counter_y)
  108.         {
  109.             sign_y_2 = (new_y - counter_y) & 0x80;
  110.             counter_y = new_y;
  111.         }
  112.  
  113.         return (((counter_y & 0x0f) << 4) | (counter_x & 0x0f));
  114.     }
  115. }
  116.  
  117. READ_HANDLER( atarifb4_in0_r )
  118. {
  119.     /* LD1 and LD2 low, return sign bits */
  120.     if ((CTRLD & 0x60)==0x00)
  121.     {
  122.         int val;
  123.  
  124.         val = (sign_x_4 >> 7) |
  125.               (sign_y_4 >> 6) |
  126.               (sign_x_2 >> 5) |
  127.               (sign_y_2 >> 4) |
  128.               (sign_x_3 >> 3) |
  129.               (sign_y_3 >> 2) |
  130.               (sign_x_1 >> 1) |
  131.               (sign_y_1 >> 0);
  132.         return val;
  133.     }
  134.     else if ((CTRLD & 0x60) == 0x60)
  135.     /* LD1 and LD2 both high, return Team 1 right player (player 1) */
  136.     {
  137.         static int counter_x,counter_y;
  138.         int new_x,new_y;
  139.  
  140.         /* Read player 1 trackball */
  141.         new_x = readinputport(4);
  142.         if (new_x != counter_x)
  143.         {
  144.             sign_x_1 = (new_x - counter_x) & 0x80;
  145.             counter_x = new_x;
  146.         }
  147.  
  148.         new_y = readinputport(3);
  149.         if (new_y != counter_y)
  150.         {
  151.             sign_y_1 = (new_y - counter_y) & 0x80;
  152.             counter_y = new_y;
  153.         }
  154.  
  155.         return (((counter_y & 0x0f) << 4) | (counter_x & 0x0f));
  156.     }
  157.     else if ((CTRLD & 0x60) == 0x40)
  158.     /* LD1 high, LD2 low, return Team 1 left player (player 2) */
  159.     {
  160.         static int counter_x,counter_y;
  161.         int new_x,new_y;
  162.  
  163.         /* Read player 2 trackball */
  164.         new_x = readinputport(6);
  165.         if (new_x != counter_x)
  166.         {
  167.             sign_x_2 = (new_x - counter_x) & 0x80;
  168.             counter_x = new_x;
  169.         }
  170.  
  171.         new_y = readinputport(5);
  172.         if (new_y != counter_y)
  173.         {
  174.             sign_y_2 = (new_y - counter_y) & 0x80;
  175.             counter_y = new_y;
  176.         }
  177.  
  178.         return (((counter_y & 0x0f) << 4) | (counter_x & 0x0f));
  179.     }
  180.  
  181.     else return 0;
  182. }
  183.  
  184.  
  185. READ_HANDLER( atarifb4_in2_r )
  186. {
  187.     if ((CTRLD & 0x40)==0x00)
  188.     {
  189.         return input_port_2_r(offset);
  190.     }
  191.     else if ((CTRLD & 0x60) == 0x60)
  192.     /* LD1 and LD2 both high, return Team 2 right player (player 3) */
  193.     {
  194.         static int counter_x,counter_y;
  195.         int new_x,new_y;
  196.  
  197.         /* Read player 3 trackball */
  198.         new_x = readinputport(8);
  199.         if (new_x != counter_x)
  200.         {
  201.             sign_x_3 = (new_x - counter_x) & 0x80;
  202.             counter_x = new_x;
  203.         }
  204.  
  205.         new_y = readinputport(7);
  206.         if (new_y != counter_y)
  207.         {
  208.             sign_y_3 = (new_y - counter_y) & 0x80;
  209.             counter_y = new_y;
  210.         }
  211.  
  212.         return (((counter_y & 0x0f) << 4) | (counter_x & 0x0f));
  213.     }
  214.     else if ((CTRLD & 0x60) == 0x40)
  215.     /* LD1 high, LD2 low, return Team 2 left player (player 4) */
  216.     {
  217.         static int counter_x,counter_y;
  218.         int new_x,new_y;
  219.  
  220.         /* Read player 4 trackball */
  221.         new_x = readinputport(10);
  222.         if (new_x != counter_x)
  223.         {
  224.             sign_x_4 = (new_x - counter_x) & 0x80;
  225.             counter_x = new_x;
  226.         }
  227.  
  228.         new_y = readinputport(9);
  229.         if (new_y != counter_y)
  230.         {
  231.             sign_y_4 = (new_y - counter_y) & 0x80;
  232.             counter_y = new_y;
  233.         }
  234.  
  235.         return (((counter_y & 0x0f) << 4) | (counter_x & 0x0f));
  236.     }
  237.  
  238.     else return 0;
  239. }
  240.  
  241.  
  242.